package top.sssd.spi.pf4j;

import org.pf4j.DefaultPluginFactory;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;
import top.sssd.spi.pf4j.api.PluginContext;

import java.lang.reflect.Constructor;

public class GreetingPluginFactory extends DefaultPluginFactory {
    @Override
    protected Plugin createInstance(Class<?> pluginClass, PluginWrapper pluginWrapper) {
        PluginContext context = new PluginContext(pluginWrapper.getRuntimeMode());
        try {
            Constructor<?> constructor = pluginClass.getConstructor(PluginContext.class);
            return (Plugin) constructor.newInstance(context);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return null;
    }
}
